home *** CD-ROM | disk | FTP | other *** search
- /* CPROG8.CPP - the bare bones of a menu system
-
- THIS VERSION OF THE FILE IS NOT COMMENTED SO THAT YOU CAN CLEARLY SEE
- HOW THE PROGRAM IS STRUCTURED. PROGRAM FILE CPROG8-A.CPP IS EXACTLY
- THE SAME CODE WITH LOTS OF EXPLANATORY TEXT
-
- */
-
-
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <dos.h>
- #include <ctype.h>
-
- #define BEEP sound(300); delay(500); nosound();
-
- ////////////////////////////////////
- void pause(void)
- {
- printf("\nPress a key...\n");
- while( kbhit() == 0 )
- ;
- (void)getch();
- }
-
- ////////////////////////////////////
- void showmenu(void)
- {
- clrscr();
- printf("Press...\n");
- printf("1 ... for menu item 1\n");
- printf("2 ... for menu item 2\n");
- printf("3 ... for menu item 3\n");
- printf("\nQ ... to quit\n");
- }
-
- ////////////////////////////////////
- void action1(void)
- {
- clrscr();
- printf("The program code for menu item 1\n");
- pause();
- }
-
- ////////////////////////////////////
- void action2(void)
- {
- clrscr();
- printf("The program code for menu item 2\n");
- pause();
-
- }
-
- ////////////////////////////////////
- void action3(void)
- {
- clrscr();
- printf("The program code for menu item 3\n");
- pause();
-
- }
-
- ////////////////////////////////////
- ////////////////////////////////////
- int main(void)
- {
- int kpress;
-
- while( 1 )
- {
- showmenu();
- kpress=getch();
- kpress=toupper(kpress);
- switch( kpress )
- {
- case '1':
- action1();
- break;
-
- case '2':
- action2();
- break;
-
- case '3':
- action3();
- break;
-
- case 'Q':
- exit(0);
-
- default:
- BEEP
- }
- }
- }